//
//  UIBarButItem.swift
//  weibo
//
//  Created by 张清美 on 16/3/2.
//  Copyright © 2016年 张清美. All rights reserved.
//

import UIKit

//分类
extension UIBarButtonItem {


    convenience  init(imageName:String?=nil,title:String?=nil,target:AnyObject?,action:Selector) {
        
        self.init()
        
        let button = UIButton()
        
        //btn 的点击事件
      button.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        
        if let name = imageName {
        
            //设置 button 的不同状态下的背景图片
            button.setImage(UIImage(named: name), forState: UIControlState.Normal)
            
            
            button.setImage(UIImage(named: "\(name)_highlighted"), forState: UIControlState.Highlighted)
        
        
        
        }
        
        if let t = title {
        
            //如果有文字 那么就去设置文字
           button.setTitle(t, forState: UIControlState.Normal)
            
            //设置不同状态下的文字颜色
            button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)
            
            
            button.setTitleColor(UIColor(colorLiteralRed: 52/255, green: 52/255, blue: 52/255, alpha: 1), forState: UIControlState.Normal)
            
            
            
            //设置文字的字体
            button.titleLabel?.font = UIFont.systemFontOfSize(14)
            
            
            
            
            
        
        
        }
        
        button.sizeToFit()
        
        
        customView = button
        

        
        
        
        
        
    }







}